﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration; // must add this...
using System.Data.SqlClient; // must add this...
using System.Data; // must add this...


namespace ErrorLog
{
    internal class LogToDB : ILog
    {
        
        public void logNow(string strError)
        {
            string connection_string = ConfigurationSettings.AppSettings["dsn"];
            lock (this)
            {
                SqlConnection conn = new SqlConnection(connection_string);
                List<string> errors = new List<string>();

                try
                {
                    string strSQL = "insert_errolog";

                    SqlDataAdapter mySA = new SqlDataAdapter(strSQL, conn);
                    mySA.SelectCommand.CommandType = CommandType.StoredProcedure;
                    mySA.SelectCommand.Parameters.Add(new SqlParameter("@errorMsg", SqlDbType.VarChar, 50));
                    mySA.SelectCommand.Parameters.Add(new SqlParameter("@errorTime", SqlDbType.DateTime));

                    mySA.SelectCommand.Parameters["@errorMsg"].Value = strError;
                    mySA.SelectCommand.Parameters["@errorTime"].Value = DateTime.Now;

                    DataSet myDS = new DataSet();
                    mySA.Fill(myDS);


                }
                catch (Exception e)
                {

                    errors.Add("Error: " + e.ToString());
                }
                finally
                {
                    conn.Dispose();
                    conn = null;
                }

            }

        }
    }
}
